//
//  BLItem.swift
//  BLLiveTelecast
//
//  Created by BigL055 on 16/5/21.
//  Copyright © 2016年 bigL.liveTelecast.com. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    class func bl_BarButtonItem(norImage norImage : UIImage?,
                                         highImage : UIImage?,
                                         target : AnyObject?,
                                         action : Selector,
                                         forControlEvents : UIControlEvents = .TouchUpInside)-> UIBarButtonItem {
        
        let leftBtn = UIButton(type: .Custom)
        
        //norImage - nil值判断
        var norImage = norImage
        if  norImage == nil{
            norImage = UIImage()
        }
        
        //norImage - nil值判断
        var highImage = highImage
        if highImage == nil {
            highImage = UIImage()
        }
        
        leftBtn.setImage(norImage, forState: .Normal)
        leftBtn.setImage(highImage, forState: .Highlighted)
        leftBtn.sizeToFit()
        leftBtn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        let containView = UIView(frame: leftBtn.bounds);
        containView.addSubview(leftBtn)
        
        return UIBarButtonItem(customView: containView)
    }
    
}

